﻿using System;
using System.Collections;
using VitCode.Castle.Entities;

namespace AMS.Core.Entities
{
    /// <summary>
    /// 区域对象
    /// </summary>
    public class Area : BaseEntity
    {
        private string m_Code;
        private string m_Name;
        private Area m_Parent;

        /// <summary>
        /// 名称
        /// </summary>
        public virtual string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        /// <summary>
        /// 编码
        /// </summary>
        public virtual string Code
        {
            get { return m_Code; }
            set { m_Code = value; }
        }

        /// <summary>
        /// 父菜单
        /// </summary>
        public virtual Area Parent
        {
            get { return m_Parent; }
            set
            {
                if (value != null && value == this)
                    throw new ArgumentException("不是设置本节点为父节点");
                m_Parent = value;
            }
        }

        /// <summary>
        /// 节点树模型的层次信息
        /// </summary>
        public virtual string OrderId { get; set; }

        /// <summary>
        /// 重写Equals方法
        /// </summary>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
                return true;
            if (obj == null)
                return false;
            var sObj = obj as Area;
            return sObj != null && (sObj.Id == m_Id || ((sObj.Name == m_Name) && (sObj.Code == m_Code)));
        }

        /// <summary>
        /// 重写GetHashCode方法
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 111;
            hash = 11*hash*m_Id.GetHashCode();
            return hash;
        }

        /// <summary>
        /// 重写ToString方法
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_Name;
        }

        public ArrayList GetRelateObjectInfo()
        {
            var al = new ArrayList();
            al.Add(new[] {typeof (Site).Name, "o.Area.Id='" + m_Id + "'", m_Name});
            al.Add(new[] {typeof (Area).Name, "o.Parent.Id='" + m_Id + "'", m_Name});
            return al;
        }
    }
}